<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/12/7
 * Time: 11:09
 */

namespace app\zyhsapi\controller\v5;

use app\zyhsapi\controller\ZyhsAuth;
use app\zyhsapi\model\comment\ZyhsArticleComment;
use app\zyhsapi\model\comment\ZyhsArticleCommentReply;
use app\zyhsapi\model\ZyhsPxyzUserQuestion;
use app\zyhsapi\model\ZyhsTag;
use app\zyhsapi\model\ZyhsUserReport;
use think\response\Json;

class Complain extends ZyhsAuth
{

    /**
     * 举报
     * @return Json|void
     * @throws \Exception
     */
    public function report()
    {
        $type = input('type/d', 0);//1=>平行宇宙问题  2=>平行宇宙评论  3=>平行宇宙回复
        $dataId = input('data_id/d', 0);
        $id = input('id/d', 0);
        $appeaTag = (new ZyhsTag())->getTag(2);
        if (empty($appeaTag[$id]))
        {
            return show(config('code.error'), '举报标签不存在');
        }
        switch ($type)
        {
            case 1:
                $data = (new ZyhsPxyzUserQuestion())->getInfoById($dataId, ['id']);
                break;
            case 2:
                $data = (new ZyhsArticleComment())->getInfoById($dataId, ['id']);
                break;
            case 3:
                $data = (new ZyhsArticleCommentReply())->getInfoById($dataId, ['id']);
                break;
            default:
                return show(config('code.error'), '请求异常');
        }
        if (!$data)
        {
            return show(config('code.error'), '举报数据不存在');
        }
        (new ZyhsUserReport())->insert([
            'type' => $type + 1,
            'data_id' => $dataId,
            'tid' => $id,
            'uid' => $this->user['id'] ?? '',
            'create_time' => $this->request->time(),
        ]);
        return show(config('code.success'), '举报成功');
    }
}
